<% layout('/layout/default.html', {title: '字典管理', libs: ['dataGrid','icheck']}){ %>
<div class="main-content">
    <div class="card-header">
        <i class="fa fa-sitemap"></i> 字典管理
        <div class="header-tools float-right">
            <a href="#" class="btn btn-default btn-sm" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
            <% if(hasPermi('sys:dict:edit')){ %>
            <a href="/sys/dict/form?sort=10" class="btn btn-default btn-sm btnTool" title="字典添加"><i class="fa fa-plus"></i> 新增</a>
            <% } %>
        </div>
    </div>
    <div class="container-fluid">
        <form id="searchForm" action="${ctx}/sys/dict/listAll" class="form-inline d-none">
            <div class="form-group">
                <label class="control-label">类型：</label>
                <div class="control-inline">
                    <#form:select path="type" name="type" value="type" data="${typeList}" class="form-control select2bs4" />
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">描述：</label>
                <div class="control-inline">
                    <input name="description" class="form-control form-control-sm"/>
                </div>
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-success btn-sm ">查询</button>
                <button id="reset" type="reset" class="btn btn-default btn-sm">重置</button>
            </div>
        </form>
        <table id="dataGrid"></table>
        <div id="dataGridPage"></div>
    </div>
</div>
<% } %>
<script>
    $.fn.select2.defaults.set('width', '200px');

    $('#dataGrid').dataGrid({
        searchForm: $("#searchForm"),
        columnModel: [
            {header:'键值', name:'value', index:'value', width:50, align:"center"},
            {header:'标签', name:'label', index:'label', width:50, align:"center"},
            {header:'类型', name:'type', index:'type', width:50, align:"center"},
            {header:'描述', name:'description', index:'description', width:80, align:"center"},
            {header:'排序', name:'sort', index:'sort', width:50, align:"center"},
            {header:'更新时间', name:'updateDate', index:'update_date', width:80, align:"center"},
            {header:'操作', name:'actions', width:80, align:"center",sortable:false, title:false, formatter: function(val, obj, row, act){
                    var actions = [];
                <% if(hasPermi('sys:dict:edit')){ %>
                        actions.push('<a href="/sys/dict/form?id='+row.id+'" class="btnList" title="编辑字典信息"><i class="fas fa-pencil-alt"></i></a>&nbsp&nbsp');
                        actions.push('<a href="${ctx}/sys/dict/delete?id='+row.id+'" class="btnList" title="删除字典" data-confirm="确认要删除字典信息吗?"><i class="far fa-trash-alt"></i></a>&nbsp&nbsp');
                        actions.push('<a href="/sys/dict/form?type='+row.type+'&description='+row.description+'&sort='+(row.sort+10)+'" class="btnList" title="添加键值"><i class="fa fa-plus-square"></i></a>');
                    <% } %>
                    return actions.join('');
                }}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data){

        }
    });
</script>

<script type="text/javascript">
    $('#reset').click(function(){
        $('#type').val(null).trigger("change");
    });

</script>